import { Axios } from '@axios/base'
import { HttpStatus } from '@axios/base/http_status';
import { Project } from '@entity/project'

export class ProjectBase extends Axios {

    constructor() {
        super('project');
    }

    /** 
     * GET /project/list
     * 获取项目列表
     */
    async projectList(): Promise<Array<Project>> {
        const result = await this.get<Array<Project>>('/all')
        return result.status == HttpStatus.SUCCESS ? result.data : [];
    }

    /** 
     * GET /project/single
     * 获取单个项目
     */
    async project(id: number): Promise<Project> {
        const result = await this.get<Project>('/query', {
            params: {
                id: id
            }
        })
        return result.status == HttpStatus.SUCCESS ? result.data : new Project();
    }

    /** 
     * GET /project/positions
     * 获取职位/分工
     */
    async getTags(): Promise<Array<string>> {
        const result = await this.get<Array<string>>('/positions')
        return result.status == HttpStatus.SUCCESS ? result.data : [];
    }

    /** 
     * POST /project/publish
     * 发布项目
     */
    async publish(project: Project): Promise<Boolean> {
        const result = await this.post<Boolean>('/publish', project)
        return result.status == HttpStatus.SUCCESS ? result.data : false;
    }

}

export default new ProjectBase();